//
//  WebViewController.m
//  GiftSay
//
//  Created by QQn1993 on 16/1/8.
//  Copyright © 2016年 liyinkai. All rights reserved.
//

#import "WebViewController.h"

@interface WebViewController ()<UIWebViewDelegate,UIScrollViewDelegate>

@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"礼物详情";
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"分享" style:UIBarButtonItemStylePlain target:self action:@selector(share)];
    
    UIWebView *web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.size.width, self.view.size.height - 10)];
    web.scrollView.delegate = self;
    
    NSURLRequest *relod = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
    
    if ([self.type isEqualToString:@"html"]) {
        [LYKNetWorkTool getWithUrl:self.url parameter:nil httpHeader:nil resposeType:ResponseTypeDATA success:^(id result) {
            
            id any = [NSJSONSerialization JSONObjectWithData:result options:0 error:nil];
//            NSLog(@"%@",any);
            NSDictionary *data = any[@"data"];
            NSString *html = data[@"content_html"];
            
            [web loadHTMLString:html baseURL:[NSURL URLWithString:self.url]];
            
        } fail:^(NSError *erro) {
            
        }];
    }
    else if ([self.type isEqualToString:@"itemshtml"]){
        [LYKNetWorkTool getWithUrl:self.url parameter:nil httpHeader:nil resposeType:ResponseTypeDATA success:^(id result) {
            
            id any = [NSJSONSerialization JSONObjectWithData:result options:0 error:nil];
//            NSLog(@"%@",any);
            NSDictionary *data = any[@"data"];
            NSString *html = data[@"detail_html"];
            
            NSLog(@"%@",html);
            
            [web loadHTMLString:html baseURL:[NSURL URLWithString:self.url]];
            
        } fail:^(NSError *erro) {
            
        }];

    }
    else{
        [web loadRequest:relod];
    }
    
    [self.view addSubview:web];
    
    // Do any additional setup after loading the view.
}

- (void)share
{
    NSLog(@"分享");
}

- (void)viewDidAppear:(BOOL)animated
{
    self.navigationController.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.tabBarController.tabBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
